package lx;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Date;
public class demo4 {
    public static void main(String[] args) throws ParseException {
        //请使用代码实现计算你活了多少天，用JDK7和JDK8两种方式完成
        //JDK7
        //规则:只要对时间进行计算或者判断，都需要先获取当前时间的毫秒值
        //1.计算出生年月日的毫秒值
        String birthday = "2002年9月19日";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
        Date date = sdf.parse(birthday);
        long birthdaytime = date.getTime();
        Date d=new Date();
        long time = d.getTime();
        long sum = time - birthdaytime;
        sum=sum/1000/60/60/24;
        System.out.println(sum);
        //JDK8
        LocalDate ld1=LocalDate.now();
        LocalDate ld2=LocalDate.of(2002,9,19);
        long day = ChronoUnit.DAYS.between(ld2, ld1);
        System.out.println(day);
    }
}
